package util;

import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

public class EmailUtil {

	private static final String user = "wsw19892008@163.com";
	private static final String password = "3056592";
	private static final String host="smtp.163.com";

	public static void sendEmail(String recivicers, String attachments) {
		HtmlEmail email = new HtmlEmail();
	
		try {
			email.setHostName(host);
			email.setCharset("utf-8");
			if(recivicers!=null&&recivicers!=""){
				String[] recivicer = recivicers.split(";");
				for(String s : recivicer){
					email.addTo(s);
				}
			}
			if(attachments!=null&&attachments!=null){
				String[] attachment = attachments.split(";");
				for(String s :attachment){
					EmailAttachment a = new EmailAttachment();
					a.setPath(s);
					a.setDisposition(EmailAttachment.ATTACHMENT);
					email.attach(a);
				}
			}
			email.setFrom("wsw19892008@163.com");
			email.setAuthentication(user, password);
			email.setSubject("测试邮件标题");
			email.setHtmlMsg("测试<a href='www.baidu.com'>百度</a>");
			email.send();
		} catch (EmailException e) {
			e.printStackTrace();
		}
	}
}
